package com.ming.Servlet;

import com.alibaba.fastjson.JSON;
import com.ming.DaoImp.EmailUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by Administrator on 2018/8/16 0016.
 */
@WebServlet(name = "EmailServlet")
public class EmailServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        EmailUtil ds = new EmailUtil();
        String email = request.getParameter("email");
        String to = email;           // 收件人邮箱地址
        String text = "你好，</br><h1>，</h1></br>无需回复。";//内容主体
        String title = "测试邮件";//邮件标题
      boolean flag =  ds.sendMail(to, text, title);
      /* if(flag){
           System.out.println("发送成功");
       }else{
            System.out.println("发送失败");
        }*/
        String json = JSON.toJSONString(flag);
        out.print(json);
        out.flush();
        out.close();

}

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
